import { ref } from 'vue'

import { defineStore } from 'pinia'

export const useConsultStore = defineStore(
	'consult',
	() => {
		// 患者的病情数据
		const consult = ref({})
		
		// 设置病情数据
		const setConsult = (val) => {
			consult.value.illnessDetail = val.illnessDetail
			consult.value.illnessTime = val.illnessTime
			consult.value.consultFlags = val.consultFlags
			consult.value.pictures = val.pictures
		}
		
		// 清除数据
		const clearConsult = () => {
			consult.value = {}
		}
		
		// 保存科室id
		const setDepId = (val) => {
			consult.value.depId = val
		}
		
		// 保存问诊类型
		const setType = (val) => {
			consult.value.type = val
		}
		
		// 保存illnessType
		const setIllnessType = (val) => {
			consult.value.illnessType = val
		}
		
		return {
			consult,
			setConsult,
			clearConsult,
			setDepId,
			setType,
			setIllnessType
		}
	},
	{
		persist: {
			storage: {
				setItem: (key, value) => {
					uni.setStorageSync(key, value)
				},
				getItem: (key) => {
					return uni.getStorageSync(key)
				}
			}
		}
	}
)